package cn.com.HiSting1990.suanfa;

import javax.swing.*;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Random;
import java.util.stream.Collectors;

//排序
public class myPaiXu {
    static int a = 0;
    static List<Integer> list;
    static List<Integer> listTemp;
    public static void getNumber(List<Integer> list){
        a = 0;
        for (Integer i:list) {
            if (a != list.size()-1)
                System.out.print(i+", ");
            else System.out.print(i);
            a++;
        }
    }

    public static void getListNumber(){
        Random random = new Random();
        a = 0;
        while (a != 10){
            listTemp.add(random.nextInt(100));
            //使用Java8特性去重
            list = listTemp.stream().distinct().collect(Collectors.toList());
            a++;
        }
    }

    public static void paixu() {

        for (int i=0;i<list.size()-1;i++){
            for (int j=0;j<list.size()-1-i;j++){
                if (list.get(j)>list.get(j+1)){
                    int temp = list.get(j);
                    list.set(j,list.get(j+1));
                    list.set(j+1,temp);
                }
            }
        }
        System.out.println();
        for (Integer i:list) {
            System.out.print(i+", ");
        }
    }

    public static void main(String[] args) {
        list = new ArrayList<>();
        listTemp = new ArrayList<>();
        getListNumber();
        getNumber(list);
//        list.sort(new Comparator<Integer>() {
//            @Override
//            public int compare(Integer o1, Integer o2) {
//                return o1.compareTo(o2);
//            }
//        });
        System.out.println();
        paixu();
//        getNumber(paixu());
    }

}
